@extends('layouts.app')
@section('content')
        <div class="container mt-3" style="background:white;">
        <ul role="tablist" class="nav nav-tabs">
            <li class="nav-item"><a href="/store" class="nav-link">店铺列表</a></li>
            <li class="nav-item"><a href="#" class="nav-link active">添加店铺</a></li>
        </ul>
        <form action="/store" method="post">
            <div class="card-body card-body-contrast">
                @csrf
                <div class="form-group row">
                    <label for="name" class="col-12 col-sm-3 col-form-label text-md-right">店铺名称</label>
                    <div class="col-12 col-md-9">
                        <input id="name" name="name" type="text"
                               value="{{ $mall['name']??old('name') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('name') ? ' is-invalid' : '' }}">
                        @if ($errors->has('name'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('name') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="content" class="col-12 col-sm-3 col-form-label text-md-right"  style="padding-top:initial;">店铺分类</label>
                    <div class="col-12 col-sm-8 col-lg-6">
                        <select class="form-control" name="cid">
                            @foreach($cates as $cate)
                                <option value="{{$cate['id']}}" selected="">{{$cate['cname']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label for="run" class="col-12 col-sm-3 col-form-label text-md-right">经营范围</label>
                    <div class="col-12 col-md-9">
                        <input id="run" name="run" type="text"
                               value="{{ $mall['run']??old('run') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('run') ? ' is-invalid' : '' }}">
                        @if ($errors->has('run'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('run') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="introduct" class="col-12 col-sm-3 col-form-label text-md-right">简介</label>
                    <div class="col-12 col-md-9">
                        <input id="introduct" name="introduct" type="text"
                               value="{{ $mall['introduct']??old('introduct') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('introduct') ? ' is-invalid' : '' }}">
                        @if ($errors->has('introduct'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('introduct') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="address" class="col-12 col-sm-3 col-form-label text-md-right">地址</label>
                    <div class="col-12 col-md-9">
                        <input id="address" name="address" type="text"
                               value="{{ $mall['address']??old('address') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('address') ? ' is-invalid' : '' }}">
                        @if ($errors->has('address'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('address') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="phone" class="col-12 col-sm-3 col-form-label text-md-right">联系电话</label>
                    <div class="col-12 col-md-9">
                        <input id="phone" name="phone" type="text"
                               value="{{ $mall['phone']??old('phone') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('phone') ? ' is-invalid' : '' }}">
                        @if ($errors->has('phone'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('phone') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="ewm" class="col-12 col-sm-3 col-form-label text-md-right">二维码</label>
                    <div class="col-12 col-lg-9">
                        <hd-image name="ewm" id="ewm" image-url="{!! $mall['ewm']??old('ewm') !!}"></hd-image>
                        @if ($errors->has('ewm'))
                            <span class="text-danger">
                <strong>{{ $errors->first('ewm') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="face" class="col-12 col-sm-3 col-form-label text-md-right">店铺封面</label>
                    <div class="col-12 col-lg-9">
                        <hd-image name="face" id="face" image-url="{!! $mall['face']??old('face') !!}"></hd-image>
                        @if ($errors->has('face'))
                            <span class="text-danger">
                <strong>{{ $errors->first('face') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="dianzhao" class="col-12 col-sm-3 col-form-label text-md-right">店招</label>
                    <div class="col-12 col-lg-9">
                        <hd-image name="dianzhao" id="dianzhao" image-url="{!! $mall['dianzhao']??old('dianzhao') !!}"></hd-image>
                        @if ($errors->has('dianzhao'))
                            <span class="text-danger">
                <strong>{{ $errors->first('dianzhao') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="dianzhao" class="col-12 col-sm-3 col-form-label text-md-right">店铺图片集</label>
                    <div class="col-12 col-lg-9">
                        <hd-images name="src" :image-url="[]"></hd-images>
                        @if ($errors->has('src'))
                            <span class="text-danger">
                <strong>{{ $errors->first('src') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row">
                    <label for="link" class="col-12 col-sm-3 col-form-label text-md-right">外链地址</label>
                    <div class="col-12 col-md-9">
                        <input id="link" name="link" type="text"
                               value="{{ $mall['link']??old('link') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('link') ? ' is-invalid' : '' }}">
                        @if ($errors->has('link'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('link') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <input type="hidden" name="owner" readonly value="{{auth()->user ()->id}}">
                <div class="form-group row">
                    <label for="position" class="col-12 col-sm-3 col-form-label text-md-right">店铺定位</label>
                    <div class="col-12 col-md-9">
                        <input placeholder="请在地图中选择您店铺的具体位置" readonly id="position" name="position" type="text"
                               value="{{ $mall['position']??old('position') }}"
                               class="form-control form-control-sm form-control{{ $errors->has('position') ? ' is-invalid' : '' }}">
                        @if ($errors->has('position'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('position') }}</strong>
            </span>
                        @endif
                    </div>
                </div>
                <div class="form-group row" style="height:600px;">
                    <div class="col-md-3 p-0" style="width:0px;"></div>
                    <div class="col-12 col-md-9" style="border:1px solid #eee;border-radius: 5px;padding:5px;">
                        <div id="container" style="width:100%;height:100%;"></div>
                    </div>
                </div>


            </div>
            <div class="card-footer text-muted">
                <button class="btn btn-primary offset-sm-2">保存提交</button>
            </div>
        </form>
        </div>
@endsection
@section('scripts')
    <script>
        var map = new BMap.Map("container");
        map.centerAndZoom(new BMap.Point(117.65401,24.51893), 16);
        map.enableScrollWheelZoom();
        map.addEventListener("click", function(e){
            map.clearOverlays();
            $('#position').val(e.point.lng+','+e.point.lat);
            // alert(e.point.lng + ", " + e.point.lat);
            var point=new BMap.Point(e.point.lng,e.point.lat);
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);               // 将标注添加到地图中
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        });
    </script>
@endsection
